package com.example.busshop.controller;

import com.example.busshop.common.controller.LogicController;
import com.example.busshop.common.service.LogicService;
import com.example.busshop.config.R;
import com.example.busshop.dao.CustomerDao;
import com.example.busshop.entity.Customer;
import com.example.busshop.entity.Item;
import com.example.busshop.entity.LineItem;
import com.example.busshop.entity.Order;
import com.example.busshop.service.CustomerService;
import com.example.busshop.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/customer")
public class CustomerController extends LogicController<CustomerService, CustomerDao, Customer,Long> {
    @Resource
    CustomerService customerService;
    public CustomerController(@Autowired CustomerService customerService) {
        super(customerService);
    }
    @PostMapping("/create")
    public Order create(@RequestParam Long Id, @RequestParam Long sId,@RequestBody Set<LineItem> lineItems){
        return customerService.createOrder(Id,sId,lineItems);
    }
    @PostMapping("/cancel")
    public Object cancel(@RequestParam Long oid){
        Map<String,Object> map=new HashMap<>();
        if(customerService.cancel(oid)>0) {
            map.put("status","已取消");
            map.put("code",200);
            return map;
        }
        else return "取消失败";
    }
    @PostMapping ("/pay")
    public R pay(@RequestParam Long Id){
        Map<String,Object> map=new HashMap<>();
        if(customerService.payOrder(Id)>0);

        return R.ok().message("已支付");
    }
    @PostMapping("/chooseItem")
    public Order choose(@RequestParam Long Id,@RequestParam Double quantity,@RequestBody Item item){
        return customerService.chooseItem(Id,item,quantity);
    }
    @GetMapping("/allOrder")
    public Set<Order> MyOrderList(@RequestParam Long Id){
        return customerService.MyallOrder(Id);
    }
}
